/**
 * 
 */
package ar.edu.utn.frsf.cidisi.ginet.generation.upcolbpip2cginet.elementsestructure;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;

import ar.edu.utn.frsf.cidisi.ginet.GINet;
import ar.edu.utn.frsf.cidisi.ginet.abstractginet.AbstractginetFactory;
import ar.edu.utn.frsf.cidisi.ginet.abstractginet.Page;
import ar.edu.utn.frsf.cidisi.ginet.generation.upcolbpip2cginet.elementstemplate.InteractionProtocolStructure;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.BusinessMessage;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionProtocol;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionProtocolElement;

/**
 * @author Neri
 *
 */
public class UpColbpipStructureToAbstractPage{
	
	private Page pageStructure;
	
	private GINet ginet;
	
	private InteractionProtocol rootElement;
	
	public UpColbpipStructureToAbstractPage(GINet ginet, InteractionProtocol rootElement){
		super();
	
		this.rootElement = rootElement;
		this.pageStructure = AbstractginetFactory.eINSTANCE.createPage();
		this.ginet = ginet;
		this.initializeStructure();
	}

	private void initializeStructure() {
		
		

		InteractionProtocolStructure interactionProtocolStructure = new InteractionProtocolStructure(this.rootElement.getIpElement(),this.ginet.getDeclaration());	
	

		Page page = interactionProtocolStructure.createInteractionProtocol(1, this.getAllBusinessMessages() );
		
		this.ginet.getDeclaration().addAll(interactionProtocolStructure.getGinetDeclarations());
		
		this.pageStructure = page;
	}

	private EList<BusinessMessage> getAllBusinessMessages() {
		EList<BusinessMessage> result = new BasicEList<BusinessMessage>();
		
		for (InteractionProtocolElement businessMessage : this.rootElement.getIpElement()) {
			if(businessMessage instanceof BusinessMessage){
				result.add((BusinessMessage)businessMessage);
			}
		}
		return result;
	}

	public Page getAbstractPage(){
		return this.pageStructure;
	}
}
